package com.xilihui.xlh.business.widget;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.xilihui.xlh.R;
import com.xilihui.xlh.core.util.ToastUtil;
import com.xilihui.xlh.core.util.YEventBuses;

/**
 * Created by Administrator on 2018/5/18.
 */

public class StorePopWindow extends PopupWindow implements View.OnClickListener {
    
    public static final String STORE_SIFT = "store_sift";
    
    private View view;
    private TextView tv_volue;
    private TextView tv_time;
    private TextView tv_jianxu;
    private TextView tv_shengxu;
    
    
    public StorePopWindow(Activity context){

        view = LayoutInflater.from(context).inflate(R.layout.popup_store,null);
        initView();
        this.setContentView(view);
        this.setWidth(LayoutParams.WRAP_CONTENT);
        this.setHeight(LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        this.setAnimationStyle(R.style.AnimationPreview);
        
    }
    
    public void initView(){

        tv_volue = (TextView)view.findViewById(R.id.tv_spxl);
        tv_time = (TextView)view.findViewById(R.id.tv_time);
        tv_jianxu = (TextView)view.findViewById(R.id.tv_jiagejiangxu);
        tv_shengxu = (TextView)view.findViewById(R.id.tv_jiageshengxu); 
        
        tv_volue.setOnClickListener(this);
        tv_time.setOnClickListener(this);
        tv_jianxu.setOnClickListener(this);
        tv_shengxu.setOnClickListener(this);
        
    }
    
    public void show(View view){
        if(view!=null){
            showAsDropDown(view,0,-20);
        }
    }

    @Override
    public void onClick(View view) {
        dismiss();
        switch (view.getId()){
            case R.id.tv_spxl:
                ToastUtil.toastShortPositive("商品销量排序");
                YEventBuses.post(new YEventBuses.Event(STORE_SIFT).setParams("1"));
                break;
            case R.id.tv_time:
                ToastUtil.toastShortPositive("商品发布时间排序");
                YEventBuses.post(new YEventBuses.Event(STORE_SIFT).setParams("2"));
                break;
            case R.id.tv_jiagejiangxu:
                ToastUtil.toastShortPositive("价格降序");
                YEventBuses.post(new YEventBuses.Event(STORE_SIFT).setParams("3"));
                break;
            case R.id.tv_jiageshengxu:
                ToastUtil.toastShortPositive("价格升序");
                YEventBuses.post(new YEventBuses.Event(STORE_SIFT).setParams("4"));
                break;
        }
    }
}
